package entity.characters;

import model.Model;

import org.lwjgl.util.vector.Vector3f;

import entity.MovingEntity;
import entity.weapon.RocketLauncher;
import entity.weapon.Shot;
import entity.weapon.Weapon;

/**
 * 
 * @author Jevgeni Krutov
 *
 */
public class Character extends MovingEntity {
	private Vector3f jumpingForce;
	private boolean isGrounded = false;
	protected int health;
	
	protected boolean isShooting = false;
	protected Weapon weapon;

	public Character(Vector3f position, Vector3f rotation, Model model, int health) {
		super(position, rotation);
		setModel(model);
		this.setMass(75f);
		this.health = health;
		weapon = new RocketLauncher(this);
		jumpingForce = new Vector3f(0, 800f, 0);
	}
	
	public int getHealth() {
		return health;
	}

	public void applyDamage(int damage) {
		this.health -= damage;
	}
	
	@Override
	public boolean isCharacter() {
		return true;
	}
	
	@Override
	public boolean isAlive() {
		return health > 0;
	}
	
	public boolean isShooting() {
		if(isShooting) {
			isShooting = false;
			return true;
		}
		return false;
	}
	
	public Shot shoot(long elapsedTime) {
		if(weapon == null) {
			return null;
		}
		return weapon.emitShot(elapsedTime);
	}
	
    protected void jump() {
		this.applyForce(jumpingForce);
		isGrounded = false;
	}
	
	public Weapon getWeapon() {
		return weapon;
	}
	
	public boolean isGrounded() {
		return isGrounded;
	}
	
	public void setGrounded(boolean isGrounded) {
		this.isGrounded = isGrounded;
	}
}
